<?php
	class service extends common{
		private $table_service='zs_service';						//服务表
		private $table_service_class='zs_service_class';			//服务分类表
		private $table_service_album='zs_service_album';			//服务相册表
		private $user_collection_table="user_collection";			//会员收藏表
		private $table_service_comment="zs_service_comment";		//会员评价表
		private $table_user="user";									//会员表

		private $province="pcc_province";		//省
		private $city="pcc_city";				//市
		private $county='pcc_county';			//区


		function __construct(){
			parent::__construct();
		}

		/**
		 * 服务分类      
		 * @return array 
		 * @author jsy        
		 */
		function serviceClassList($where=''){
			$where.=' order by c.id asc';
			$sql=$this->table_service_class.' c where 1=1 '.$where;
			$key='c.*';
			$list=$this->getList($sql,$key,$num=0);
			return $list;
		}

		/**
		 * 服务列表
		 * @param  string  $where 
		 * @param  string  $key   
		 * @param  integer $num 	分页：每页数量  
		 * @return array  
		 * @author jsy       
		 */
		function serviceList($where='',$key='i.*',$num=0){
			$sql=$this->table_service.' i
				  where 1=1 '.$where;
			$key.='';
			$key.=',(select province from '.$this->province.' where provinceid=i.province) as provinceName';
			$key.=',(select city from '.$this->city.' where cityid=i.city) as cityName';
			$list=$this->getList($sql,$key,$num);
			$class=$this->serviceClassList();				//分类
			if(is_array($list['result'])){
				foreach($list['result'] as $k=>$v){
					if(is_array($class['result'])){
						foreach($class['result'] as $key=>$val){
							if($v['class_id']==$val['id']){
								$list['result'][$k]['className']=$val['class_name'];
							}
						}
					}
				}
			}
			return $list;
		}

		/**
		 * 服务详情
		 * @param  string $where 
		 * @param  string $Key   
		 * @return array
		 * @author wxy        
		 */
		function serviceInfo($where='',$key='s.*'){
			$sql=$this->table_service.' s where 1=1 '.$where;
			$key.=',(select province from '.$this->province.' where provinceid=s.province) as provinceName';
			$key.=',(select city from '.$this->city.' where cityid=s.city) as cityName';
			$key.=',(select county from '.$this->county.' where countyid=s.county) as countyName';
			$info=$this->getInfo($sql,$key);
			return $info;
		}

		/**
		 * 服务点击量+1
		 * @param  [type] $where 
		 * @return         
		 */
		function serviceClickAdd($where){
			$sql='UPDATE '.$this->table_service.' SET click_num=click_num+1 where '.$where;
			$res=$this->query($sql);
		}

		/**
		 * 服务相册
		 * @param  string  $where 
		 * @param  string  $key   
		 * @param  integer $num  取多少相册 
		 * @return array
		 * @author wxy         
		 */
		function serviceAlbumList($where='',$key='sa.*',$num=0){
			$sql=$this->table_service_album.' sa where 1=1 '.$where;
			$sql.=$num!=0?' limit 0,'.$num:'';
			$list=$this->getList($sql,$key,0);
			return $list;
		}

		/**
		 * 会员收藏服务列表
		 * @param  string  $key 
		 * @param  integer $num 
		 * @return array       
		 */
		function serviceCollectList($key="*",$num=0){
			$user_id=$_COOKIE['user_id'];			//会员id
			$sql=$this->user_collection_table.' c left join '.$this->table_service.' s on c.type_id=s.id 
				  where c.user_id="'.$user_id.'" 
				  and c.type="service" order by c.create_time desc';
			$list=$this->getList($sql,$key,$num);
			return $list;
		}

		/**
		 * 删除收藏
		 * @param  int $id        
		 * @param  string $searchKey 
		 * @return bool            
		 */
		function collectDel($id,$searchKey='id'){
			$res=$this->del($this->user_collection_table,$id.',','',$searchKey);
			return $res;
		}


		/**
		 * 服务评论
		 * @author	jsy 
		 * @param	string	$where  
		 * @param	string	$key  
		 * @return 	array
		 */
		function serviceComment($where='',$key="*"){
			$sql = $this->table_service_comment." a LEFT JOIN ".$this->table_user." u ON a.user_id=u.id LEFT JOIN ".$this->table_user." u1 ON a.reply_id=u1.id WHERE 1=1  ".$where." order by a.create_time desc" ;
			$res=$this->getList($sql,$key);
			return $res ;
		}
		
	}
?>